Fix ends_with missing overlapping suffix matches - #93
Open
gaoflow wants to merge 1 commit into
Open
Conversation
find() yields non-overlapping matches, so ends_with returned false for a
genuine suffix that overlaps an earlier occurrence ("hahaha".ends_with("haha")).
Scan each suffix with the same anchored is_equal check PartialEq uses, which
also keeps starts_with untouched.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 52 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ends_withisself.find(other).last().end == len, butfindyields non-overlapping matches, so a real suffix that overlaps an earlier match is never emitted and the check returns false:Same for
"banana".ends_with("ana")and the confusable core casecure!("bаnаnа").ends_with("ana").starts_withis start-anchored, so it was already correct — only theends_withsibling was affected.Fix: scan each suffix with the same anchored
is_equalthatPartialEquses, soends_withis true iff some suffix similarly-equals the needle. Non-suffixes still return false ("hahaha".ends_with("hah")) andstarts_with/containsare unchanged. Added asimilar_ends_withtest (overlap, repeated/separated/leetspeak/confusable suffixes, whole-string, empty, non-suffix);cargo test --all-featurespasses.